home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1993 September / September 93.iso / Archives / Applications / Calculators / NumberCrunch 1.41 / Number Crunch II Demo / Writing External Codes (xCOD) / Pascal source code / SCHRODINGER.p < prev    next >
Encoding:
Text File  |  1992-08-16  |  2.5 KB  |  66 lines  |  [TEXT/PJMM]

  1. {This is Pascal source code which will compile into}
  2. {an xCOD (eXternal CODe) resource for NumberCrunch II.}
  3. {}
  4. {All variables passed MUST be declared var and }
  5. {MUST be extended or array of extended or external procedures.}
  6. {}
  7. { After building this code resource you must install it into NumberCrunch with either ResEdit or the}
  8. { Load xCOD command from inside NCII. }
  9. {}
  10. { In either case, an sCOD string or resource is also needed to tell NCII what the arguments to this routine are.}
  11. {     For this routine, the appropriate sCOD is:}
  12. {}
  13. {        xCOD xSCHRODINGER(N,C,E:num; V,Psi:RealArray), calculates Psi[3…N] from V[1…N], Psi[1],Psi[2],Energy, and C=dx^2*2m/hbar^2   }
  14. {}
  15. {    (Of course, the sCOD string doesn't include the braces at the beginning and end of the line.)  }
  16. {}
  17. { •••••••••••••••••••••••••••••}
  18. { •••••••• SCHRODINGER ••••••••• }
  19. { •••••••••••••••••••••••••••••}
  20. {}
  21. { This routine calculates Psi, the time-independent wavefunction, from V(x) and E. The equation is}
  22. {          -hbar^2 ∂^2/∂x^2  Psi(x)   + V(x) Psi(x)   = E Psi(x)    }
  23. {  or     Psi[i+1]  - 2 Psi[i] + Psi[i-1]  =   C ( V[i] - E ) Psi[i]   }
  24. {    where Psi [ i ] = a discrete version of Psi [ x ] }
  25. {              V[i]        = a discrete V(x), and}
  26. {              C =  Δx^2 * 2m/hbar^2 .}
  27. {}
  28. {  The program just loops from i=2 to N-1 applying   Psi[i+1]  = 2 Psi[i] - Psi[i-1] + C* (V[i] - E )*Psi[i].  }
  29. {}
  30. {    If V is even, then the wavefunction will be even or odd, so good choices for Psi[1] and Psi[2]  are }
  31. {  [a,a]  or  [a,-a] for any number a . ( Psi isn 't normalized yet, so the value of "a" doesn' t really matter.)  }
  32. {  The 1st choice forces Psi to be even near x=0, while the 2nd makes it odd.}
  33. {}
  34. {}
  35. { INPUTS:}
  36. {                 N                          number of points in arrays}
  37. {                C                        constant = Δx^2 * 2m / hbar^2  }
  38. {                E                        the energy of the wavefunction}
  39. {                V                [1..N] array of points giving V(x), the potential. All must bet set. }
  40. {                Psi                [1..N] array of points for wavefunction. Psi[1] and Psi[2] must be set on input. }
  41. {OUTPUT:}
  42. {                Psi                        Psi[3..N] are calculated by this subroutine.}
  43.  
  44. unit SCHRODINGER;
  45. interface
  46.     uses
  47.         SANE;
  48.  
  49.     type
  50.         ExtendedArrayType = array[1..1] of extended;
  51.  
  52.     procedure Main (var N, C, E: extended; {}
  53.                                     var V, Psi: ExtendedArrayType);
  54.  
  55. implementation
  56.  
  57.     procedure Main;
  58.         var
  59.             intN, i: Integer;
  60.     begin
  61.         intN := Num2Integer(N);   {Num2Integer is a routine in the SANE library to convert extended to integer.}
  62.         for i := 2 to (intN - 1) do
  63.             Psi[i + 1] := Psi[i] * (2.0 + C * (V[i] - E)) - Psi[i - 1];
  64.     end; {Main}
  65.  
  66. end.